package jym.tan.movielibrary.component.renderer;

import java.awt.Component;
import java.util.Locale;

import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;

import jym.tan.movielibrary.constant.ComponentConstant;

import org.apache.commons.lang.StringUtils;

public class StringCellRenderer extends DefaultTableCellRenderer {

	private static final long serialVersionUID = 59L;

	public StringCellRenderer() {
		super();
		setOpaque(true);
		setHorizontalAlignment(CENTER);
	}
	
	@Override
	public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
		if(value != null) {
			if(column == ComponentConstant.ColumnName.LANGUAGE.getOrder()) {
				this.setText(new Locale(value.toString()).getDisplayLanguage());
			} else if(column == ComponentConstant.ColumnName.CERTIFICATION.getOrder()) {
				this.setText(StringUtils.upperCase(value.toString()));
			} else {
				this.setText(value.toString());
			}
		} else {
			this.setText("");
		}
		return this;
	}	
} 
